package com.hzcx.app.simplechat.ui.user.presenter;

import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.model.FriendModel;
import com.hzcx.app.simplechat.model.UserModel;
import com.hzcx.app.simplechat.ui.friend.bean.FriendLableListBean;
import com.hzcx.app.simplechat.ui.publicui.bean.HxUserInfoBean;
import com.hzcx.app.simplechat.ui.user.contract.UserLableSettingContract;
import com.hzcx.app.simplechat.ui.user.contract.UserRemarkContract;
import com.hzcx.app.simplechat.util.UserInfoUtil;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;

import org.litepal.LitePal;

import java.util.List;

public class UserLableSettingPresenter extends BasePresenter<UserLableSettingContract.View> implements UserLableSettingContract.Presenter {

    /**
     * 获取所有标签列表
     *
     * @param context
     */
    @Override
    public void getLableList(Context context) {
        FriendModel.getFriendLableList(context, new BaseDialogObserver<List<FriendLableListBean>>(context) {
            @Override
            protected void onSuccess(List<FriendLableListBean> data) {
                mView.lableResult(data);
            }
        });
    }

    /**
     * 设置好友标签
     *
     * @param context
     * @param id
     * @param data
     */
    @Override
    public void setUserLable(Context context, int id, List<FriendLableListBean> data) {

        String nams = "";
        for (int i = 0; i < data.size(); i++) {
            if (EmptyUtils.isEmpty(data.get(i).getName())) {
                continue;
            }
            if (i == 0) {
                nams = data.get(i).getName();
            } else {
                nams = nams + "," + data.get(i).getName();
            }
        }

        UserModel.setUserLable(context, id, nams, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.setSuccess();
            }
        });
    }
}
